package com.aaa.power.controller;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.power.entity.UserRole;
import com.aaa.power.service.UserRoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户和角色关联表(UserRole)表控制层
 *
 * @author makejava
 * @since 2020-11-12 20:30:16
 */
@RestController
@RequestMapping("userRole")
public class UserRoleController {
    /**
     * 服务对象
     */
    @Resource
    private UserRoleService userRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param userRole 主键
     * @return 单条数据
     */
    @GetMapping("queryAll")
    public Result queryAll(UserRole userRole) {
        return this.userRoleService.queryAll(userRole);
    }

    @GetMapping("insert")
    public Result insert(Integer userId, String roleIds){
        System.out.println(roleIds);
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(), userRoleService.insert(userId,roleIds));
    }

    @GetMapping("deleteById")
    public Result deleteById(Integer userId){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(), userRoleService.deleteById(userId));
    }

}